#include "csapp.h"

#define MAX_CACHE_SIZE 1049000
#define MAX_OBJECT_SIZE 102400

/* the object contains HTTP header and body
 * record bodysize here for convience
 */
struct Object
{
    char* head;
    char* body;
    int bodysize;
};

/* Block struct for element of cache
 * organized as one-way linked list
 */
struct Block{
    char *uri;
    struct Object *object;
    struct Block *next;
};

struct Block * cache_list;

void init_cache();
void add_node(struct Block *block);
void remove_node(struct Block *block);
void move_to_tail(struct Block *block);
int is_full(int size);
int is_empty();
struct Block * get_head();
struct Block * get_tail();
char* pack_uri(char* host, char *path, int port);
int init_container(void);

struct Object * visit_cache(char *uri);
int update_cache(char *uri, struct Object *object);


